﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataProvider
{
    [Serializable]
    public class SageVersion: IEqualityComparer<SageVersion>
    {
        public SageVersion()
        {
        }
        public SageVersion(Version version)
        {
            MajorVersion = version.Major;
            MinorVersion = version.Minor;
            Build = version.Build;
            Revision = version.Revision;
        }

        [Key]
        public int Id { get; set; }
        public int MajorVersion { get; set; }
        public int MinorVersion { get; set; }
        public int Build { get; set; }
        public int Revision { get; set; }

        public int CompareTo(SageVersion other)
        {
            return this.IsSameAs(other) ? 0 : 1;
        }

        private bool IsSameAs(SageVersion version)
        {
            return this.MajorVersion == version.MajorVersion
                && this.MinorVersion == version.MinorVersion
                && this.Build == version.Build
                && this.Revision == version.Revision;
        }

        public bool Equals(SageVersion x, SageVersion y)
        {
            return x.MajorVersion == y.MajorVersion
                && x.MinorVersion == y.MinorVersion
                && x.Build == y.Build
                && x.Revision == y.Revision;
        }

        public override string ToString()
        {
            return string.Format("{0}.{1}.{2}.{3}", MajorVersion, MinorVersion, Build, Revision);

        }

        public int GetHashCode(SageVersion obj)
        {
            return obj.ToString().GetHashCode();
        }
    }
}
